import static org.junit.Assert.*;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * This class is to unit test the VendingMachineItem class functinality 
 * @author Viji
 *
 */
public class VendingMachineItemTest {
		
	/** Test the constructor
	 * Input: Give a negative value for price of Vending Machine Item.
	 * Output: Method should throw exception
	 */
	@Test  
	public void testVendingMachineItem() {
		try{
			VendingMachineItem VMItem1 = new VendingMachineItem("VMItem1", -10.0);
			fail("Should have thrown an VendingMachineException because price is invalid!");
		} 
		catch (VendingMachineException e) {
			assertEquals( "Price cannot be less than zero",e.getMessage());
		}
	}
	
	
	
	/** Test the getName() method
	 * Input: Create a new vending machine item object with a name and price
	 * Output: Method should return the name of vending machine item created.
	 */
	@Test
	public void testGetName(){
		VendingMachineItem VMItem1 = new VendingMachineItem("VMItem1", 50.0);
		assertEquals("VMItem1", VMItem1.getName());
	}
	
	
	@Test
	public void testGetName1(){
		VendingMachineItem VMItem1 = new VendingMachineItem("", 50.0);
		assertEquals("", VMItem1.getName());
	}
	
	
	/** Test the getPrice() method
	 * Input: Create a new vending machine item object with a name and price
	 * Output: Method should return the price of vending machine item created.
	 */
	@Test
	public void testGetPrice(){
		VendingMachineItem VMItem1 = new VendingMachineItem("VMItem1", 50.0);
		assertEquals(50.0, VMItem1.getPrice(), 0.01);
	}
	
	@Test
	public void testGetPrice1(){
		VendingMachineItem VMItem1 = new VendingMachineItem("VMItem1", 0.0);
		assertEquals(0.0, VMItem1.getPrice(), 0.01);
	}

}
	

